package com.animatedpicture.object;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;

import javax.swing.ImageIcon;

public class Vocalist implements IMovingObject {
	private Point Pos;

	private int ch = 0;
	private boolean ani_Flag = false;
	private final int one_X = -15,two_X = -10, three_X = 20;
	private final int one_Y = 10,two_Y = 20,three_Y = 10;

	private String headType;
	private ImageIcon headImg;

	public Vocalist(String headType){
		Pos = null;

		this.headType = headType;

		switch (this.headType) {
		case "Default":
			headImg = null;
			break;
		case "Yap Che Een":
			headImg = new ImageIcon("./Image/Yap.png");
			break;
		case "Kim Ik Soo":
			headImg = new ImageIcon("./Image/Kim.png");
			break;
		case "Wong Kok Sheng":
			headImg = new ImageIcon("./Image/Wong.png");
			break;
		case "Shin Yong Tae":
			headImg = new ImageIcon("./Image/Shin.png");
			break;
		case "Kim Seock Yoon":
			headImg = new ImageIcon("./Image/Kim_S.png");
			break;
		default:
			break;
		}
	}


	public void draw(Graphics2D g2) {

		if( Pos != null ){
			Ellipse2D.Double HEAD = new Ellipse2D.Double(Pos.x, Pos.y, 30, 30);
			Line2D.Double BODY = new Line2D.Double(Pos.x + 15, Pos.y + 30, Pos.x + 15,
					Pos.y + 90);

			Line2D.Double LEFT_el = new Line2D.Double(Pos.x + 15, Pos.y + 35,
					Pos.x - 5, Pos.y + 50);
			Line2D.Double LEFT_arm = new Line2D.Double(Pos.x - 5, Pos.y + 50,
					Pos.x + 5, Pos.y + 60);

			Line2D.Double RI_el = new Line2D.Double(Pos.x + 15, Pos.y + 35, Pos.x + 35,
					Pos.y + 50);
			Line2D.Double RI_arm = new Line2D.Double(Pos.x + 35, Pos.y + 50, Pos.x + 5,
					Pos.y + 70);


			Line2D.Double LEFT_kne = new Line2D.Double(Pos.x + 15, Pos.y + 90, Pos.x + 5 ,
					Pos.y + 100);
			Line2D.Double LEFT_fot = new Line2D.Double(Pos.x + 5 , Pos.y + 100, Pos.x + 5 ,
					Pos.y + 130);

			Line2D.Double RI_kne = new Line2D.Double(Pos.x + 15, Pos.y + 90, Pos.x + 25,
					Pos.y + 100);
			Line2D.Double RI_fot = new Line2D.Double(Pos.x + 25, Pos.y + 100, Pos.x + 25,
					Pos.y + 130);

			Ellipse2D.Double Mike_head = new Ellipse2D.Double( Pos.x + 5 , Pos.y + 30, 15, 10 );
			Line2D.Double Mike_body = new Line2D.Double(Pos.x + 5, Pos.y + 35, Pos.x + 5,
					Pos.y + 120);

			Line2D.Double foot1 = new Line2D.Double( Pos.x + 5, Pos.y + 120 , Pos.x + 5 + one_X, Pos.y + 120 + one_Y);
			Line2D.Double foot2 = new Line2D.Double( Pos.x + 5, Pos.y + 120 , Pos.x + 5 + two_X, Pos.y + 120 + two_Y);
			Line2D.Double foot3 = new Line2D.Double( Pos.x + 5, Pos.y + 120 , Pos.x + 5 + three_X, Pos.y + 120 + three_Y);

			g2.setColor( Color.black );

			if( ani_Flag == true ){
				ch = ( ch + 1 ) % 2;
			}

			Graphics g = (Graphics)g2;

			if( ch == 0 ){
				HEAD = new Ellipse2D.Double(Pos.x, Pos.y, 30, 30);

				if (headImg != null) {
					g.drawImage(headImg.getImage(),Pos.x-5, Pos.y-5, 40, 40, null);
				}

				BODY = new Line2D.Double(Pos.x + 15, Pos.y + 30, Pos.x + 15,
						Pos.y + 90);

				LEFT_el = new Line2D.Double(Pos.x + 15, Pos.y + 35,
						Pos.x - 5, Pos.y + 50);
				LEFT_arm = new Line2D.Double(Pos.x - 5, Pos.y + 50,
						Pos.x + 5, Pos.y + 60);

				RI_el = new Line2D.Double(Pos.x + 15, Pos.y + 35, Pos.x + 35,
						Pos.y + 50);
				RI_arm = new Line2D.Double(Pos.x + 35, Pos.y + 50, Pos.x + 5,
						Pos.y + 70);


				LEFT_kne = new Line2D.Double(Pos.x + 15, Pos.y + 90, Pos.x + 5 ,
						Pos.y + 100);
				LEFT_fot = new Line2D.Double(Pos.x + 5 , Pos.y + 100, Pos.x + 5 ,
						Pos.y + 130);

				RI_kne = new Line2D.Double(Pos.x + 15, Pos.y + 90, Pos.x + 25,
						Pos.y + 100);
				RI_fot = new Line2D.Double(Pos.x + 25, Pos.y + 100, Pos.x + 25,
						Pos.y + 130);
			}
			else if( ch == 1 ){
				HEAD = new Ellipse2D.Double(Pos.x, Pos.y + 5, 30, 30);

				if (headImg != null) {
					g.drawImage(headImg.getImage(),Pos.x-5, Pos.y, 40, 40, null);
				}

				BODY = new Line2D.Double(Pos.x + 15, Pos.y + 30 + 5, Pos.x + 15,
						Pos.y + 90 + 5 + 10);

				LEFT_el = new Line2D.Double(Pos.x + 15, Pos.y + 35 + 5,
						Pos.x - 5, Pos.y + 50 + 5);
				LEFT_arm = new Line2D.Double(Pos.x - 5, Pos.y + 50 + 5, 
						Pos.x + 5, Pos.y + 60 + 5);

				RI_el = new Line2D.Double(Pos.x + 15, Pos.y + 35 + 5, Pos.x + 35,
						Pos.y + 50 + 5);
				RI_arm = new Line2D.Double(Pos.x + 35, Pos.y + 50 + 5, Pos.x + 5,
						Pos.y + 70 + 5);


				LEFT_kne = new Line2D.Double(Pos.x + 15, Pos.y + 90 + 5 + 10, Pos.x + 5 ,
						Pos.y + 100 + 5);
				LEFT_fot = new Line2D.Double(Pos.x + 5 , Pos.y + 100 + 5, Pos.x + 5 ,
						Pos.y + 130 + 5);

				RI_kne = new Line2D.Double(Pos.x + 15, Pos.y + 90 + 5 + 10, Pos.x + 25,
						Pos.y + 100 + 5);
				RI_fot = new Line2D.Double(Pos.x + 25, Pos.y + 100 + 5, Pos.x + 25,
						Pos.y + 130 + 5);
			}
			else if( ch == 2 ){
				HEAD = new Ellipse2D.Double(Pos.x, Pos.y, 30, 30);

				if (headImg != null) {
					g.drawImage(headImg.getImage(),Pos.x-5, Pos.y-5, 40, 40, null);
				}

				BODY = new Line2D.Double(Pos.x + 15, Pos.y + 30, Pos.x + 15,
						Pos.y + 90);

				LEFT_el = new Line2D.Double(Pos.x + 15, Pos.y + 35,
						Pos.x - 15, Pos.y + 30);
				LEFT_arm = new Line2D.Double(Pos.x - 15, Pos.y + 30,
						Pos.x - 20 + 5, Pos.y);

				RI_el = new Line2D.Double(Pos.x + 15, Pos.y + 35, Pos.x + 35,
						Pos.y + 50);
				RI_arm = new Line2D.Double(Pos.x + 35, Pos.y + 50, Pos.x + 20,
						Pos.y + 70);


				LEFT_kne = new Line2D.Double(Pos.x + 15, Pos.y + 90, Pos.x ,
						Pos.y + 100);
				LEFT_fot = new Line2D.Double(Pos.x , Pos.y + 100, Pos.x ,
						Pos.y + 130);

				RI_kne = new Line2D.Double(Pos.x + 15, Pos.y + 90, Pos.x + 30,
						Pos.y + 100);
				RI_fot = new Line2D.Double(Pos.x + 30, Pos.y + 100, Pos.x + 30,
						Pos.y + 130);

				g2.fillOval( Pos.x - 20 - 5 + 5, Pos.y - 5, 10, 10);
			}
			else if( ch == 3 ){
				HEAD = new Ellipse2D.Double(Pos.x-5, Pos.y, 40, 40);

				if (headImg != null) {
					g.drawImage(headImg.getImage(),Pos.x, Pos.y + 5, 30, 30, null);
				}

				BODY = new Line2D.Double(Pos.x + 15, Pos.y + 30 + 5, Pos.x + 15,
						Pos.y + 100 + 5);

				LEFT_el = new Line2D.Double(Pos.x + 15, Pos.y + 35 + 5,
						Pos.x - 15, Pos.y + 30 + 5);
				LEFT_arm = new Line2D.Double(Pos.x - 15, Pos.y + 30 + 5,
						Pos.x - 20, Pos.y + 5);

				RI_el = new Line2D.Double(Pos.x + 15, Pos.y + 35 + 5, Pos.x + 35,
						Pos.y + 50 + 5);
				RI_arm = new Line2D.Double(Pos.x + 35, Pos.y + 50 + 5, Pos.x + 20,
						Pos.y + 70 + 5);


				LEFT_kne = new Line2D.Double(Pos.x + 15, Pos.y + 100 + 5, Pos.x ,
						Pos.y + 100 + 5);
				LEFT_fot = new Line2D.Double(Pos.x , Pos.y + 100 + 5, Pos.x ,
						Pos.y + 130 + 5);

				RI_kne = new Line2D.Double(Pos.x + 15, Pos.y + 100 + 5, Pos.x + 30,
						Pos.y + 100 + 5);
				RI_fot = new Line2D.Double(Pos.x + 30, Pos.y + 100 + 5, Pos.x + 30,
						Pos.y + 130 + 5);

				g2.fillOval( Pos.x - 20 - 5, Pos.y - 5, 10, 10);
			}

			g2.setStroke( new BasicStroke( 3 ) );
			g2.setColor( Color.blue );
			if (headImg == null) {
				g2.fill(HEAD);
				g2.draw(HEAD);
			}
			g2.draw(BODY);
			g2.draw(LEFT_arm);
			g2.draw(LEFT_el);
			g2.draw(RI_arm);
			g2.draw(RI_el);

			g2.draw(LEFT_fot);
			g2.draw(LEFT_kne);
			g2.draw(RI_fot);
			g2.draw(RI_kne);


			g2.setColor( Color.black );

			g2.draw(foot1);
			g2.draw(foot2);
			g2.draw(foot3);


			g2.draw(Mike_head);
			g2.fill(Mike_head);

			g2.draw(Mike_body);
		}
	}

	public void setPosition(Point mPoint) {
		Pos = mPoint;
		System.out.println("ObjectCar SetPosition : ("+mPoint.x+","+mPoint.y+")");
	}

	@Override
	public void animate(boolean trriger) {
		ani_Flag = trriger;	
	}


	@Override
	public void playMusic(boolean trriger) { }
}
